package com.school.device.util;

import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;

public final class DataConvertUtil {
	
	private static SimpleDateFormat dateFormat=new SimpleDateFormat("yyyyMMdd");
	
	private static SimpleDateFormat timeFormat=new SimpleDateFormat("HHmmssSSS");
	

	public static String getObjectStr(Map<String,Object> object,String key){
		Object valObj=object.get(key);
		if(valObj==null)
			return null;
		return String.valueOf(valObj);
	}
	
	public static Integer getObjectInt(Map<String,Object> object,String key){
		Object valObj=object.get(key);
		if(valObj==null)
			return 0;
		return Integer.valueOf(String.valueOf(valObj));
	}
	
	public static Float getObjectFloat(Map<String,Object> object,String key){
		Object valObj=object.get(key);
		if(valObj==null)
			return null;
		return Float.valueOf(String.valueOf(valObj));
	}
	
	public static Double getObjectDouble(Map<String,Object> object,String key){
		Object valObj=object.get(key);
		if(valObj==null)
			return null;
		return Double.valueOf(String.valueOf(valObj));
	}	
	
	public static Long getObjectLong(Map<String,Object> object,String key){
		Object valObj=object.get(key);
		if(valObj==null)
			return null;
		return Long.valueOf(String.valueOf(valObj));
	}
	
	public static Byte getObjectByte(Map<String,Object> object,String key){
		Object valObj=object.get(key);
		if(valObj==null)
			return null;
		return Byte.valueOf(String.valueOf(valObj));
	}
	
	public static List<Map<String,Object>> getObjectList(Map<String,Object> object,String key){
		Object valObj=object.get(key);
		if(valObj==null)
			return null;
		return (List<Map<String,Object>>)valObj;
	}
		
	public static Integer getDate(Long millSeconds) {
		if(millSeconds==null)
			return null;
		Date date=new Date(millSeconds);
		String format=dateFormat.format(date);
		return Integer.valueOf(format);
	}
	
	public static Integer getTime(Long millSeconds) {
		if(millSeconds==null)
			return null;
		Date date=new Date(millSeconds);
		String format=timeFormat.format(date);
		return Integer.valueOf(format);
	}
	
}
